Some LB users have wanted to use a large number of textboxes in their program. Here is a graphics approach. Some features of this demo are:
' manyTextboxes.bas
' Use graphicbox to draw many textboxes.
' Edit a group at a time with real textboxes.
' Written for LB3 in win98, Oct 2003 by Bill Jennings.
nSets=72 '*** number of data sets
nVar=3 '*** number of data variables
maxBoxes=24 '*** number of boxes per column
DIM dat$(nVar,nSets) '*** data values
DIM xBox(nVar,nSets) '*** x-coordinates
DIM yBox(nSets) '*** y-coordinates
heading$=" RPM TORQUE HORSEPOWER"
gosub [assignSampleData] '*** values to display
nomainwin
WindowWidth=640 : WindowHeight=480
UpperLeftX=(DisplayWidth-WindowWidth)/2
UpperLeftY=(DisplayHeight-WindowHeight)/2
menu #w1,"&Options", "&Help",[help], "E&xit",[quit]
graphicbox #w1.g1,4,4,WindowWidth-16,WindowHeight-52
textbox #w1.tb1,0,0,0,0 'box for editing RPM value
textbox #w1.tb2,0,0,0,0 'box for editing Torque value
textbox #w1.tb3,0,0,0,0 'box for editing Horsepower value
open space$(44)+"Many (graphics) Textboxes" for window as #w1
print #w1, "trapclose [quit]"
print #w1.g1, "font Arial 8"
print #w1.tb1, "!font Arial 8"
print #w1.tb2, "!font Arial 8"
print #w1.tb3, "!font Arial 8"
print #w1.g1, "down; fill lightgray"
gosub [initBoxes]
goto [keyboard]
[quit]
close #w1 : END
[keyboard] '*** detect keypress or mouse click
print #w1.g1, "when characterInput [keyDown]"
print #w1.g1, "when leftButtonDown [leftClick]"
print #w1.g1, "setfocus"
[scanKeys]
'API call saves system resources:
calldll #kernel32,"Sleep",1 as ulong, res as void
SCAN
goto [scanKeys]
[keyDown]
key$=Inkey$ : enter=0
if len(key$)<2 then
ndx=asc(key$)
else
ndx=asc(mid$(key$,2,1))
end if
'*** control keys:
if ndx=120 or ndx=88 then [quit] '*** X key ends program
if ndx=13 then '*** Enter key has been pressed
if flagBox then '*** some boxes may have been edited
'*** redo all boxes after retrieving edited values
print #w1.tb1, "!contents? a$" : dat$(1,nData)=a$
print #w1.tb2, "!contents? a$" : dat$(2,nData)=a$
print #w1.tb3, "!contents? a$" : dat$(3,nData)=a$
'*** move textboxes offscreen
print #w1.tb1, "!locate 0 0 0 0";
print #w1.tb2, "!locate 0 0 0 0";
print #w1.tb3, "!locate 0 0 0 0";
print #w1, "refresh"
print #w1.g1, "delsegment segID" '*** free memory
'*** redraw all boxes after retrieving edited values
gosub [drawBoxes]
flagBox=0
end if
end if
goto [scanKeys]
[leftClick] '*** find which data set was clicked
nY=int((maxBoxes-1)/382*(MouseY-maxBoxes))+1
group=int(1/208*MouseX)+1
nData=(group-1)*maxBoxes+nY 'number in array
gosub [edit_nData]
goto [scanKeys]
'-------------------------------------------
[edit_nData]
'Provide textboxes for editing selected nData set:
row=nData-int((nData-1)/maxBoxes)*maxBoxes
yBox=int(400/maxBoxes*(row-1))+20
group=int((nData+maxBoxes-1)/maxBoxes)
xBox=(group-1)*208+7
print #w1.tb1, "!locate ";xBox+5;" ";yBox+5;" 65 20";
print #w1.tb2, "!locate ";xBox+69;" ";yBox+5;" 65 20";
print #w1.tb3, "!locate ";xBox+133;" ";yBox+5;" 65 20";
print #w1, "refresh"
print #w1.tb1, dat$(1,nData)
print #w1.tb2, dat$(2,nData)
print #w1.tb3, dat$(3,nData)
print #w1.tb1, "!setfocus"
flagBox=1
RETURN
[printNum] '*** also right justify the value
print #w1.g1, "stringwidth? n$ width"
xRJ=x+60-width
print #w1.g1,"place ";xRJ;" ";y+13;
print #w1.g1, "\";n$
RETURN
[drawBox]
wide=66 : deep=18
print #w1.g1, "size 1; color buttonface"
print #w1.g1, "place ";x;" ";y
print #w1.g1, "boxfilled ";x+wide;" ";y+deep
print #w1.g1, "color white"
print #w1.g1, "place ";x;" ";y
print #w1.g1, "box ";x+wide;" ";y+deep
print #w1.g1, "color black"
print #w1.g1, "line ";x+1;" ";y+1;" ";x+1;" ";y+deep-2
print #w1.g1, "line ";x+1;" ";y+1;" ";x+wide-2;" ";y+1
RETURN
[initBoxes]
'*** make 3 column headings
print #w1.g1,"backcolor lightgray"
for h=1 to nVar
x=xBox(1,(maxBoxes+1)*(h-1))
if h>1 then x=x-8
print #w1.g1,"place ";x;" 16;\";heading$
next h
[drawBoxes] '*** draw boxes and print values
for j=1 to nSets
y=yBox(j)
for h=1 to nVar
x=xBox(h,j) : gosub [drawBox]
n$=dat$(h,j) : gosub [printNum]
next h
next j
print #w1.g1, "segment segID"
print #w1.g1, "flush"
RETURN
[assignSampleData] '*** These are just sample numbers. Alternatively,
'data could be input from a file or DATA lines.
for j=1 to nSets
dat$(1,j)=str$(1)+str$(j) '*** RPMs (or whatever)
dat$(2,j)=str$(2)+str$(j) '*** Torque (or whatever)
dat$(3,j)=str$(3)+str$(j) '*** Horsepower (or whatever)
next j
[assignBoxCoordinates] 'Alternatively, each yBox and xBox could be hard-coded.
for j=1 to nSets
row=j-int((j-1)/maxBoxes)*maxBoxes
yBox(j)=382/(maxBoxes-1)*(row-1)+20
group=int((j-1)/maxBoxes)+1
xBox(1,j)=(group-1)*208+6
xBox(2,j)=(group-1)*208+70
xBox(3,j)=(group-1)*208+134
next j
RETURN
[help]
'*** LB's Popup window will wrap the lines automatically!
cc$=chr$(13)+chr$(13) '*** space down an empty line
hlp$="To edit a value, left click in the box. "+_
"All three boxes in the group will be enabled for editing."+cc$+_
"Tab (forward or backward) between the three boxes and make "+_
"desired changes until the caret has been tabbed offscreen. "+_
"When it is not visible, press Enter. The changes will be "+_
"incorporated in a screen redraw."+cc$+_
"The program can be ended from the Options | Exit menu, or "+_
"by pressing the X-key. See the [keyboard] module for the X-key method."+cc$+_
"COMMENT:"+cc$+_
"The three grouped variables in this demo are shown as not mathematically "+_
"related. The code could be altered to select only one or two of them, "+_
"with the others changed to new values via the appropriate math."
WindowWidth=612 : WindowHeight=416
UpperLeftX=UpperLeftX+14 : UpperLeftY=UpperLeftY+52
BackgroundColor$ = "cyan"
statictext #w2, hlp$, 10,10,WindowWidth-10,WindowHeight-100
button #w2.b1, " Return to program ",[closeW2],UL,200,360
open "" for window_popup as #w2
print #w2, "font Arial 11"
WAIT
[closeW2]
close #w2
'*** restore window #w1
WindowWidth=640 : WindowHeight=480
UpperLeftX=(DisplayWidth-WindowWidth)/2
UpperLeftY=(DisplayHeight-WindowHeight)/2
goto [keyboard]
'--------------------------------------------